

<?php


if ($this->code == "0"){
    echo "<legend>";
    echo $this->msg;
    echo "</legend>";
}else echo $this->msg;

if ($this->code == ""){    

?>
<legend>Kirim SMS ke semua Downline</legend>
<div class="row clearfix">
<div class="col-md-6 column">
<form method="post" id="frm" name="frm">
            
                <!-- Member form -->

                

                
                <!-- old_pass input-->
                <!--div class="form-group">
                    
                        <textarea id="tujuan" name="tujuan" type="text" placeholder="Nomor Tujuan"
                         required class="form-control" style="height:100px;"></textarea>
                         <p class="help-block">Dipisahkan dengan koma (,) jika lebih dari satu nomor tujuan.</p>
                    
                </div>
                <br-->
                <!-- new_pass input-->
                <div class="form-group">
                    
                        <textarea id="pesan" name="pesan" type="text" placeholder="Isi Pesan SMS"
                         maxlength='160' required class="form-control"
                         style="height:100px;"></textarea>
                         <div id='CharCountLabel1'></div>
                </div>               

                <!-- submit btn-->
                <div class="control-group">
                    <label class="control-label"></label>
                    <div class="controls">
                        <button class="btn btn-default" type="submit" id="btnSubmit" name="btnSubmit">
                        Kirim</button> <div id="div_result"></div>
                        <p class="help-block"></p>
                    </div>
                </div>

            
        </form>
    </div>
</div>

        <script>


        CharacterCount = function(TextArea,FieldToCount){
                var myField = document.getElementById(TextArea);
                var myLabel = document.getElementById(FieldToCount);
                if(!myField || !myLabel){return false}; // catches errors
                var MaxChars =  myField.maxLengh;
                if(!MaxChars){
                    MaxChars =  myField.getAttribute('maxlength') ;
                }
                if(!MaxChars){
                    return false;
                }
                var remainingChars =   MaxChars - myField.value.length;
                //myLabel.innerHTML = remainingChars+" Characters Remaining of Maximum "+MaxChars
                myLabel.innerHTML = remainingChars;
        }

        //SETUP!!
        setInterval(function(){CharacterCount('pesan','CharCountLabel1')},55);


        /* Attach a submit handler to the form */
        $("#frm").submit(function(event) {

            /* Stop form from submitting normally */
            event.preventDefault();

            /* Clear result div*/
            $("#div_result").html('');
            $("#btnSubmit").html('Memproses...');
            $("#btnSubmit").attr('disabled','disabled');


            var msg = [];

            if ($('#new_pass').val() != $('#new_pass2').val()) msg.push('<span>* Konfirmasi Password Baru tidak cocok</span>');

            if (msg.length == 0){

                /* Get some values from elements on the page: */
                var values = $(this).serialize();

                /* Send the data using post and put the results in a div */

                $.ajax({
                    url: "sendsms/",
                    type: "post",
                    data: values,
                    success: function(response, opts){
                        var cekSess = response.toUpperCase().search("SESSION TIMEOUT");

                        if (cekSess < 0){
                            var cekStatus = response.toUpperCase().search("ERROR");

                            if (cekStatus < 0){
                                $("#div_content").html(response);
                            }else{
                                var resp = response.replace('ERROR', '');


                                msg.push('<span>'+resp+'</span>');
                                $.messager.alert('Info', msg.join('<br/>'));

                                $("#btnSubmit").removeAttr('disabled');
                                $("#btnSubmit").html('Submit');
                            }

                         }else{
                            location.href='<?php echo $this->baseUrl() ?>/index/admin/msg/Session Timeout silahkan login kembali !';
                         }
                    },
                    error:function(response, opts){
                        //alert("failure");
                        $("#div_result").html(response);
                        $("#btnSubmit").removeAttr('disabled');
                    }
                });

            }
            else{
                $("#btnSubmit").removeAttr('disabled');
                $("#btnSubmit").html('Submit');
                $.messager.alert('Info', msg.join('<br/>'));                
            }           

        });

        </script>

        <?php } ?>
    